<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <h:form id="setorForm" enctype="multipart/form-data">
                <br/>
                <h2 class="title">Pesquisar Setor</h2>
                <p:growl id="messages" showDetail="false" autoUpdate="true"  /> 
                <br/>
                <p:panel id="setorPanel" style="background: none; border: none;" 
                         styleClass="container_24 clearfix">

                    <h4 class="title">Dados Gerais</h4>
                    <p:outputLabel value="Número" styleClass="grid_3" for="numero"/>
                    <p:inputText id="numero" styleClass="grid_19" value="#{managerPesquisarSetor.setor.numero}" />
                    <div class="clear"/>

                    <div class="buttonAction">
                        <p:commandButton id="pesquisarCommandButton" value="Pesquisar" icon="ui-icon-search"
                                         update="setorTable"
                                         actionListener="#{managerPesquisarSetor.pesquisar()}"
                                         styleClass="ui-priority-primary" />
                        <p:commandButton id="bt_clear" value="Limpar" icon="ui-icon-clean"
                                         actionListener="#{managerPesquisarSetor.limpar()}"
                                         update="@form" />
                    </div>

                    <p:blockUI id="BLOCK" block="resultPanel" trigger="pesquisarCommandButton, setorTable" > 
                        <p:graphicImage value="media/images/ajax-loader.gif"/>
                    </p:blockUI> 

                    <h4 class="title">Resultado</h4>
                    <p:panel id="resultPanel" style="background: none; border: none;" 
                             styleClass="container_24 clearfix ">

                        <p:dataTable id="setorTable" var="item" value="#{managerPesquisarSetor.dataModel}" 
                                     styleClass="grid_24" rowIndexVar="rowid"
                                     binding="#{managerPesquisarSetor.searchResults}"
                                     rows="5" paginator="true" lazy="true"   
                                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                     currentPageReportTemplate="{currentPage} de {totalPages}"
                                     paginatorPosition="bottom" emptyMessage="Nenhum registro encontrado"
                                     style="white-space: pre-wrap;">

                            <f:facet name="header">
                                <p:outputLabel value="Setor #{managerPesquisarSetor.searchResults.rowCount eq 0 ? '' : '('.concat(managerPesquisarSetor.searchResults.rowCount).concat(')')}"/>
                            </f:facet> 
                            <p:column headerText="Ação" width="120">
                                <p:button title="Editar"
                                          href="editarsetor.xhtml?editarSetor=#{item.id}"
                                          icon="ui-icon-pencil"/>
                                <p:button title="Visualizar"
                                          href="visualizarsetor.xhtml?visualizarSetor=#{item.id}"
                                          icon="ui-icon-zoomin">
                                    <f:param name="v" value="t"/>
                                </p:button>
                                <p:commandButton update="@form" title="Excluir"
                                                 oncomplete="dlg.show()" rendered="#{managerLayout.admin}"
                                                 icon="ui-icon-trash">
                                    <f:setPropertyActionListener target="#{managerPesquisarSetor.setorDelete}" value="#{item}" />
                                </p:commandButton>

                            </p:column>

                            <p:column headerText="Setor">
                                <h:outputText value="#{item.numero}"/>
                            </p:column>

                        </p:dataTable>

                    </p:panel>

                    <p:dialog id="modalDialog" header="Confirmação de remoção" widgetVar="dlg" modal="true" 
                              height="80" closable="false" resizable="false" >
                        <h:outputText value="Tem certeza que deseja remover este setor ?" />
                        <div class="buttonAction">
                            <p:commandButton value="Sim"
                                             actionListener="#{managerPesquisarSetor.remover()}"
                                             update="@form"
                                             icon="ui-icon-check"/>
                            <p:commandButton value="Não" icon="ui-icon-close"
                                             oncomplete="dlg.hide()" />
                        </div>
                    </p:dialog>
                </p:panel>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
